package com.googlecode.ozonbooksfinder.matefinder.actions
{
	import com.asfusion.mate.actionLists.IScope;
	import com.asfusion.mate.actions.AbstractAction;
	import com.asfusion.mate.actions.IAction;
	import com.asfusion.mate.core.ISmartObject;
	
	import flash.net.SharedObject;
	
	import mx.collections.ArrayCollection;

	public class SaveFavoritesAction extends AbstractAction implements IAction
	{
		private var favoritesSO:SharedObject = SharedObject.getLocal("favorites");
		
		public function SaveFavoritesAction()
		{
			super();
		}
		
		private var _favorites:Object;
		public function get favorites():Object
		{
			return _favorites;
		}
		public function set favorites(value:Object):void
		{
			_favorites = value;
		}
		
		override protected function run(scope:IScope):void
		{
			super.run(scope);
			
			var realFavorites:ArrayCollection;
			if(favorites is ISmartObject)
			{
				realFavorites = 
					ArrayCollection (ISmartObject(favorites).getValue(scope));
			}
			else
			{
				realFavorites = ArrayCollection (favorites);
			}
			
			favoritesSO.data.favorites = realFavorites.source;
			favoritesSO.flush();
		}
	}
}